package com.example.contentprovider;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME="student_info";
    public static final String STU_NAME="stu_name";
    public static final String STU_CLASS="stu_class";
    public static final String STU_COMPANY="stu_company";

    public DBHelper(@Nullable Context context, @Nullable String name, @Nullable  SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table "+TABLE_NAME+"(_id integer primary key autoincrement, " +
                STU_NAME+" text not null," +
                        STU_CLASS+" text," +
                        STU_COMPANY+" text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    /**
     * 插入到学生就业信息表
     * @param cv 学生信息
     * @return 新插入数据的id
     */
    public int insertStuInfo(ContentValues cv){
        return (int) getWritableDatabase().insert(TABLE_NAME,null,cv);
    }
     public int deleteStuName(String name){
       return getWritableDatabase().delete(TABLE_NAME,STU_NAME+"=?",new String[]{name});
     }
}
